package com.kongyz;

/**
 * @author kongyz
 * @date 2018/6/21 21:30
 * @Description: 双检锁/双重校验锁（DCL，即 double-checked locking） 线程安全
 */
public class Singleton4 {
    private volatile static Singleton4 instance; //添加volatile关键字保证线程安全。
    private Singleton4(){}
    public static Singleton4 getInstance(){
        if(instance==null){
            synchronized (Singleton4.class){
                if(instance==null){
                    instance=new Singleton4();
                }
            }
        }
        return instance;
    }

}
